package cc.io24.knewcafe.blog.controller;


import cc.io24.knewcafe.blog.facade.GuShiCiService;
import cc.io24.knewcafe.blog.facade.modle.GuShiCi;
import cc.io24.knewcafe.blog.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.List;

@Controller
public class HelloController {

    @Autowired
    private PostService postService;

    @Autowired
    private GuShiCiService guShiCiService;

    @RequestMapping(value = "/")
    public String index(@PageableDefault(value = 10, sort = { "createDate" }, direction = Sort.Direction.DESC)Pageable pageable, ModelMap map) throws IOException {
        List<GuShiCi> guShiCis = guShiCiService.getList(1);
        map.addAttribute("guShiCis",guShiCis);
        map.addAttribute("posts", postService.getList(pageable));
        return "index";
    }

}
